package com.auto.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.auto.entity.Task;
import com.auto.rep.TaskRep;
import com.auto.util.LOG;
import com.google.common.collect.Lists;

@Service
public class TaskScaner {
	@Autowired
	private TaskRep taskRep;
	@Autowired
	private TaskExecutor taskExecutor;

	public void scan() {
		List<Task> tasks = Lists.newArrayList(taskRep.findByFlag(1));
		LOG.info("start scan:{}", tasks.size());
		for (Task task : tasks) {
			// 执行中
			task.setFlag(2);
			taskRep.save(task);
			taskExecutor.execute(task);
		}
	}
}
